package com.xx.pmis.persistence.dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;

import com.xx.pmis.model.Function;

public class FunctionDAOImpl extends BaseHibernateDAOImpl<Function> implements FunctionDAO {

	
	public Function getFunctionByFunctionID(int functionID) {
		Function function;
		try {
			function = (Function) getSession().get(Function.class, functionID);
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return function;
	}
	
	@SuppressWarnings("unchecked")
	public List<Function> getAllFunction() {
		List<Function> functions;
		try {
			Query query = getSession().getNamedQuery("AllFunctionQuery");
			functions = query.list();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return functions;
	}
	
	@SuppressWarnings("unchecked")
	public List<Function> getAllParentFunction() {
		List<Function> functions;
		try {
			Query query = getSession().getNamedQuery("AllParentFunctionQuery");
			functions = query.list();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return functions;
	}
	
	@SuppressWarnings("unchecked")
	public List<Function> getAllFunctionByFunctionParentID(int functionParentID) {
		List<Function> functions;
		try {
			Query query = getSession().getNamedQuery("AllFunctionByFunctionParentIDQuery");
			query.setInteger("functionParentID", functionParentID);
			functions = query.list();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return functions;
	}
}
